/**切换创建时间**/
function custTime(btn) {
    var data_cliak = $(btn).attr("data-click");
    if(data_cliak === "selft"){
        $("#advance-daterange").removeClass("hidden");
        $("#starttime").val(moment().subtract("days",29).format("YYYY-MM-DD"));
        $("#endtime").val(moment().format("YYYY-MM-DD"));
    }else{
        $("#advance-daterange").addClass("hidden");
        $("#starttime").val("");
        $("#endtime").val("");
    }
    $("#custTime").find("button").each(function () {
        $(this).removeClass("btn-primary");
    });
    $(btn).addClass("btn-primary");
    //动态加载
    $JuXue.refreshTable("onSchoolTab");
}

/**导出客户资料 确认**/
function exportCustomerInfoConfire() {
    /**记录导出的数据id**/
    var ids = $("#onSchoolTab").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要导出的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].osId;
        if (i !== (ids.length - 1)) ids_arr += ",";
    }

    $.post(ctx+"seaOnschool/exportOnSchoolData",{"keyids":ids_arr},function(r){
        if (r.code === 0) {
            window.location.href = "file/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $JuXue.n_warning(r.msg);
        }
    });
}

/**分配*/
function fenpeiCustomer() {
    var ids = $("#onSchoolTab").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要导出的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].osId;
        if (i !== (ids.length - 1)) ids_arr += ",";
    }
    $.post(ctx+"seaOnschool/loadFenpeiDetail",{},function(r){
        $("#resource-modal").empty().append(r).modal('show').draggable();
    });
}

/**删除客户**/
function  deleteCustomer() {
    var ids = $("#onSchoolTab").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要导出的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].osId;
        if (i !== (ids.length - 1)) ids_arr += ",";
    }

    $JuXue.confirm({
        text: "确定删除当前选择的客户？",
        confirmButtonText: "确定删除"
    }, function() {
        $.post(ctx+"seaOnschool/onschoolFenpei",{osDealStatus:"2","ids":ids_arr},function(r){
            if (r.code === 0) {
                $JuXue.n_success(r.msg);
                $JuXue.refreshTable("onSchoolTab");
            } else {
                $JuXue.n_warning(r.msg);
            }
        });
    });
}